var t = n(require("../../libs/mini/create")), e = n(require("../../store/index")), a = (n(require("../../utils/storage")), 
require("../../api/member")), i = require("../../api/wifi");

function n(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var s = getApp();

t.default.Page(e.default, {
    use: [ "custom", "userInfo" ],
    data: {
        loading: !0,
        listLoading: !1,
        defaultAvatar: s.globalData.moduleHost + "/resources/image/default_user.png",
        memberInfo: {},
        activeList: [ {
            id: 0,
            name: "全部",
            className: "width100"
        }, {
            id: 1,
            name: "待审核",
            className: "width100"
        }, {
            id: 2,
            name: "已审核",
            className: "width100"
        } ],
        showActiveList: !1,
        search: {
            active: "",
            content: ""
        },
        popupShow: !1,
        popupDetail: {},
        popupHistoryShow: !1,
        popupHistoryDetail: {},
        yesterdayTotal: 0,
        todayTotal: 0,
        page: 1,
        finished: !1,
        list: []
    },
    onLoad: function() {
        var t = this;
        this.showLoading("数据加载中"), e.default.getUserInfo(function(e) {
            var n = e.openid;
            (0, a.getMemberInfo)({
                openid: n
            }).then(function(a) {
                t.setData({
                    memberInfo: a
                }), t.hideLoading(), t.handleConfirmSearch(), (0, i.getTotalToday)({
                    openid: e.openid
                }).then(function(e) {
                    t.setData({
                        todayTotal: e
                    });
                }), (0, i.getTotalYesterday)({
                    openid: e.openid
                }).then(function(e) {
                    t.setData({
                        yesterdayTotal: e
                    });
                });
            }).catch(function(e) {
                t.hideLoading(), s.utils.modalText(e.message || "获取新信息失败，请检查权限是否正确！").then(function() {
                    s.utils.alwaysBack();
                });
            });
        });
    },
    onReachBottom: function() {
        this.data.finished || this._fetch();
    },
    onPopupClose: function() {
        this.setData({
            popupShow: !1,
            popupHistoryShow: !1
        });
    },
    handleShowMember: function(t) {
        var a = t.currentTarget.dataset.item;
        t = this.data.memberInfo.prole, t = Object.assign({}, a, {
            prole: t
        });
        e.default.setTempData(t), wx.navigateTo({
            url: "/wifi/member/index"
        });
    },
    handleShowHistory: function(t) {
        var e = t.currentTarget.dataset.item;
        t = this.data.memberInfo.prole, t = Object.assign({}, e, {
            prole: t
        });
        this.setData({
            popupHistoryShow: !0,
            popupHistoryDetail: t
        });
    },
    showLoading: function() {
        var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", e = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1];
        this.setData({
            loading: !0
        }), wx.showLoading({
            title: t,
            mask: e
        });
    },
    hideLoading: function() {
        this.setData({
            loading: !1
        }), wx.hideLoading();
    },
    handleShowActiveList: function() {
        this.setData({
            showActiveList: !0
        });
    },
    handleCloseActiveList: function() {
        this.setData({
            showActiveList: !1
        });
    },
    handleActiveSelect: function(t) {
        t = t.detail.id, this.setData({
            "search.active": t
        });
    },
    onInputChange: function(t) {
        t = t.detail.value, this.setData({
            "search.content": t
        });
    },
    handleConfirmSearch: function() {
        this.data.listLoading || (this.setData({
            list: [],
            finished: !1,
            page: 1
        }), this._fetch());
    },
    _fetch: function() {
        var t, e, i = this;
        this.data.finished || this.data.listLoading || (this.setData({
            listLoading: !0
        }), t = this.data.page, e = this.data.memberInfo.id, e = Object.assign({}, this.data.search, {
            pid: e,
            page: t
        }), (0, a.getMemberList)(e).then(function(e) {
            var a;
            e && e.length ? (a = i.data.list, i.setData({
                finished: !1,
                listLoading: !1,
                list: a.concat(e),
                page: t + 1
            })) : 1 == t ? i.setData({
                listLoading: !1,
                finished: !0,
                list: [],
                page: 2
            }) : i.setData({
                listLoading: !1,
                finished: !0,
                page: t + 1
            });
        }).catch(function() {
            s.utils.toastText("服务器出错，获取数据失败"), i.setData({
                listLoading: !1
            });
        }));
    },
    handleInfoClick: function() {
        wx.navigateTo({
            url: "/wifi/info/index"
        });
    },
    handleMore: function(t) {
        if (1 == (t = t.currentTarget.dataset.item).active) return this.handleCheckMember({
            currentTarget: {
                dataset: {
                    id: t.id
                }
            }
        });
        this.setData({
            popupDetail: t,
            popupShow: !0
        });
    },
    handleCheckMember: function(t) {
        var e, i, n = this;
        this.data.listLoading || (e = t.currentTarget.dataset.id, i = this.data.$.userInfo, 
        wx.showActionSheet({
            itemList: [ "审核通过", "拒绝通过" ],
            success: function(t) {
                var o = +t.tapIndex + 2;
                3 == +o ? wx.showModal({
                    content: "是否拒绝该用户的申请？",
                    showCancel: !0,
                    cancelText: "取消",
                    cancelColor: "#888",
                    confirmText: "拒绝",
                    confirmColor: "#e00",
                    success: function(t) {
                        t.confirm && (n.setData({
                            listLoading: !0
                        }), (0, a.toggleMemberActive)({
                            id: e,
                            openid: i.openid,
                            active: o
                        }).then(function() {
                            var t = n.data.list.filter(function(t) {
                                return t.id != e;
                            });
                            n.setData({
                                list: t
                            }), s.utils.toastText("已拒绝"), n.setData({
                                listLoading: !1
                            });
                        }).catch(function() {
                            s.utils.toastText("操作失败"), n.setData({
                                listLoading: !1
                            });
                        }));
                    }
                }) : (n.setData({
                    listLoading: !0
                }), (0, a.toggleMemberActive)({
                    id: e,
                    openid: i.openid,
                    active: o
                }).then(function() {
                    var t = n.data.list.slice().map(function(t) {
                        return t.id == e && (t.active = 2), t;
                    });
                    n.setData({
                        list: t
                    }), s.utils.toastText("审核通过", "success"), n.setData({
                        listLoading: !1
                    });
                }).catch(function() {
                    s.utils.toastText("操作失败"), n.setData({
                        listLoading: !1
                    });
                }));
            }
        }));
    }
});